package com.cssy.yd.logic.web;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cssy.authority.service.IScUserRolewhPlaceService;
import com.cssy.base.web.BaseController;
import com.cssy.yd.logic.entity.LogicPriceDetailsDO;
import com.cssy.yd.logic.service.ILogicPriceDetailsService;
import com.cssy.yd.logic.util.SqlUtil;
import com.cssy.yd.logic.vo.LogicWhAffVO;
import com.plat.helper.JqGridHandler;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.ExcelUtil;
import com.plat.util.json.OutJsonGrid;

@Controller
@RequestMapping("/yd/logic/logicPriceDetails")
public class LogicPriceDetailsController extends BaseController<LogicPriceDetailsDO>{

	private static final String MANAGER = "/yd/logic/priceDetails/PriceDetailsManager";
	
	@Resource(name="logicPriceDetailsService")
	private ILogicPriceDetailsService logicPriceDetailsService;
	
	@Resource(name="scUserRolePlaceService")
	private IScUserRolewhPlaceService scUserRolePlaceService;
	
	public String manager(HttpServletRequest request, Model model)
			throws Exception {
		model.addAttribute("wh",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		return MANAGER;
	}

	@Override
	public void list(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		JqGridHandler hander=new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		scs.setOrderBy("wh_code,code  asc");
		SearchResult result= logicPriceDetailsService.findListByExample(scs);
		OutJsonGrid out=new OutJsonGrid(result);
		out.printJSon(response);
		}

	@Override
	public String operationForm(HttpServletRequest request, String id,
			String flag, Model model) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> save(HttpServletRequest request,
			LogicPriceDetailsDO curAP, BindingResult result, Model model)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> delete(HttpServletRequest request,
			HttpServletResponse response, Model model) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	/**
	 * 成本变化导出
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/exportExcelPoGather")
	public void exportExcelPoGather(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		scs.clearCondition();
		hander.setFilters(new String(request.getParameter("filters").getBytes(
				"ISO-8859-1"), "UTF-8")); // 转码
		hander.getWheres(scs);
		scs.setOrderBy("code  asc");
		scs.setLimitClause(null);
		SearchResult result= logicPriceDetailsService.findListByExample(scs);
		List<LogicPriceDetailsDO>  list = result.getResults();
		ExcelUtil.toExcel(list, "仓库编码:whCode┋仓库名称:whName┋产品编码:code┋产品名称:name┋单价:price┋创建时间:dctime┋创建人:dcruser┋入库数量:quantity┋总库存:sumquantity┋平均单价:sumprice","成本变化表",response);
	}
}
